﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace ATest.ActionFilters
{
    /// <summary>
    /// If isAjax is specifiled as an action argument will be populated with value from request object
    /// </summary>
    public class AjaxActionFilter : ActionFilterAttribute
    {
        const string Key = "isAjax";

        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (filterContext.ActionParameters.ContainsKey(Key))
            {
                filterContext.ActionParameters[Key] = filterContext.HttpContext.Request.IsAjaxRequest();
            }
            base.OnActionExecuting(filterContext);
        }
    }
}
